<?php

namespace App\Admin\Actions;

use App\Admin\Forms\SendOrderForm;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Traits\HasPermissions;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Dcat\Admin\Widgets\Table;

class SendOrder extends Action
{
    use LazyWidget;
    /**
     * @return string
     */
	public $title = "订单发货";

    public $id = "";


    /**
     * @return string|array|void
     */
    public function confirm()
    {
        // return ['Confirm?', 'contents'];
    }

    public function render(): Modal
    {
        parent::render();
        $id = $this->getKey();
        // 这里直接创建一个modal框 model的内容由工具表单提供，这里也需要创建一个工具表单才行
        return Modal::make()
            ->lg()
            ->title($this->title)
            ->body(SendOrderForm::make()->payload(['id'=>$this->payload['id']]))
            ->button("<button class='btn btn-sm btn-primary'>$this->title</button>"); // 这个button就是对应上面的按钮
    }


    /**
     * @param Request $request
     * @return Response
     */
    public function handle(Request $request)
    {
        // 接收参数
        $id = $this->payload['id'] ?? null;
        $this->id = $id;
    }

    public function parameters()
    {
        return [
            'key1' => 'value1',
            'key2' => 'value2',
        ];
    }


    public function html()
    {
        return <<<HTML
<span {$this->formatHtmlAttributes()} id="batch-customer-statement-select-resourc" href="javascript:void(0)"><button class="btn btn-primary dialog-create btn-mini"><i
class="feather icon-plus"></i> {$this->title()}</button></span>
HTML;
    }


    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }



}
